import Vue from 'vue'
import App from './App.vue'
//配置axios
import axios from "../node_modules/axios"
Vue.prototype.$axios = axios;
Vue.config.productionTip = false;
//配置 VantUi
import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);
//配置 VueRouter;
import VueRouter from "vue-router";
import Home from "./pages/home";
import List from "./pages/list";
import Cart from "./pages/cart";
import Mine from "./pages/mine";
import Goods from "./pages/goods";
import Search from "./pages/search";
import Details from "./pages/details";
import Lgoin from "./pages/login";
import Reg from "./pages/reg";
import Address from "./pages/address";
import Order from "./pages/order";
Vue.use(VueRouter)
let router = new VueRouter({
    routes: [{
            path: "/home",
            name: "home",
            component: Home
        },
        {
            path: "/",
            component: Home
        },
        {
            path: "/list",
            name: "list",
            component: List
        }, {
            path: "/cart",
            name: "cart",
            component: Cart
        }, {
            path: "/mine",
            name: "mine",
            component: Mine
        }, {
            path: "/goods",
            name: "goods",
            component: Goods
        }, {
            path: "/search",
            name: "search",
            component: Search
        }, {
            path: "/details",
            name: "details",
            component: Details
        }, {
            path: "/login",
            name: "login",
            component: Lgoin
        }, {
            path: "/reg",
            name: "reg",
            component: Reg
        }, {
            path: "/address",
            name: "address",
            component: Address
        }, {
            path: "/order",
            name: "order",
            component: Order
        }
    ]
});
import Vuex from "vuex";
Vue.use(Vuex);
const store = new Vuex.Store({
    state: {
        carttype: true,
        datalist: [],
        cart: 0,
        cartlist: [],
        totalPage: "",
        page: 1,
        type: 0,
        logintype: false,
    },
    mutations: {
        getGoods(state, goods) {
            axios.get(`/goods/all?page=${goods.page}&type=${goods.type}`)
                .then(res => {
                    state.datalist = res.data.list;
                    state.totalPage = res.data.totalPage;
                    for (let i = 0; i < state.datalist.length; i++) {
                        if (typeof(state.datalist[i].tag) == "string") {
                            state.datalist[i].tag = JSON.parse(
                                state.datalist[i].tag
                            );
                        }

                    }
                });
        }
    }
})
new Vue({
    router,
    store,
    render: h => h(App),
}).$mount('#app')